package com.example.databasediary;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;


public class ChangeActivity extends Activity implements View.OnClickListener {
    private Button btnConfirm,btnq,btnentry;
    private SharedPreferences sp;
    private GestureLockView changeGv;
    private String result;
    public ChangeActivity() {
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change);
        changeGv = (GestureLockView) findViewById(R.id.changeGv);
        btnConfirm = (Button) findViewById(R.id.btnConfirm);
        btnq= (Button) findViewById(R.id.btnQ);
        btnConfirm.setOnClickListener(this);
        btnq.setOnClickListener(this);
        sp = this.getSharedPreferences("config", MODE_PRIVATE);
        changeGv.setIsSetting(true);
        changeGv.setOnGestureFinishListener(new GestureLockView.OnGestureFinishListener() {
            @Override
            public void OnGestureFinish(boolean result) {

            }
            @Override
            public void OnSettingFinish(String str) {
                result = str;

            }
        });

        btnentry = (Button)findViewById(R.id.btnentry);
        btnentry.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                Intent intent0 = new Intent(ChangeActivity.this,LifeDiary.class);
                startActivity(intent0);
                finish();
            }
        });

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btnConfirm:
                SharedPreferences.Editor editor = sp.edit();
                editor.putString("pwd", result);
                editor.commit();
                Toast.makeText(ChangeActivity.this, "修改完成",
                        Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(ChangeActivity.this, MainActivity.class);
                startActivity(intent);
                break;
            case R.id.btnQ:
                finish();
            default:
                break;
        }

    }

}
